<template>
  <div class="app-container">
    <div class="search-container">
      <el-form inline>
        <el-form-item label="名称">
          <el-input />
        </el-form-item>
        <el-button type="primary">搜索</el-button>
        <el-button type="primary">导出</el-button>
      </el-form>
    </div>
    <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row>
      <el-table-column align="center" label="ID" width="95">
        <template slot-scope="scope">
          {{ scope.$index }}
        </template>
      </el-table-column>
      <el-table-column label="巡检名称">
        <template slot-scope="scope">
          {{ scope.row.name }}
        </template>
      </el-table-column>
      <el-table-column label="类目">
        <template slot-scope="scope">
          {{ scope.row.type }}
        </template>
      </el-table-column>
      <el-table-column label="地点">
        <template slot-scope="scope">
          {{ scope.row.place }}
        </template>
      </el-table-column>
      <el-table-column label="巡检人" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.author }}</span>
        </template>
      </el-table-column>
      <el-table-column label="巡检时间" width="200" align="center">
        <template slot-scope="scope">
          {{ scope.row.display_time }}
        </template>
      </el-table-column>
      <el-table-column class-name="status-col" label="状态" width="110" align="center">
        <template slot-scope="scope">
          <el-tag :type="scope.row.status | statusFilter">{{ scope.row.status | statusFilterLabel }}</el-tag>
        </template>
      </el-table-column>
      <!-- <el-table-column align="center" prop="created_at" label="Display_time" width="200">
        <template slot-scope="scope">
          <i class="el-icon-time" />
          <span>{{ scope.row.display_time }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="操作" width="150" align="center" fixed="right">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="detail(scope.row)">详情</el-button>
          <el-button type="danger" size="mini">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog :visible.sync="dialogVisible" :title="title" width="800px">
      <el-form ref="form" :model="form" label-width="120px">
        <el-form-item label="巡检任务名称">{{ form.name }}
        </el-form-item>
        <el-form-item label="巡查人">{{ form.author }}
        </el-form-item>
        <el-form-item label="任务进度">
          <el-steps :space="300" finish-status="success">
            <el-step v-for="(el, index) in processVoList" :key="index"
              :status="el.status == 1 ? 'success' : el.status == 2 ? 'finish' : 'wait'">
              <!-- <div class="step_icon" slot="icon"
                      :icon="el.numAll == el.numDone ? 'el-icon-success' : 'el-icon-warning'"></div> -->
              <div slot="title" class="step_title" :title="el.processName">{{ el.processName }}</div>
              <div slot="description" class="step_description" :description="el.percent">
                {{ el.percent }} {{ el.time }}
              </div>
            </el-step>
          </el-steps>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onCancel">确定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { getList } from '@/api/table'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        0: 'success',
        1: 'danger',
        2: 'primary',
        3: 'warning'
      }
      return statusMap[status]
    },
    statusFilterLabel(status) {
      const statusMap = {
        0: '已检',
        1: '漏检',
        2: '待检',
        3: '暂停中'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      listLoading: true,
      data: [{
        name: '巡检1',
        type: '食堂安全',
        author: 'name',
        display_time: '2023-12-24 16:10:10',
        id: '450000199302104628',
        pageviews: 1165,
        status: 0,
        place: '1273621637521463'
      }, {
        name: '巡检1',
        type: '食堂安全',
        author: 'name',
        display_time: '2023-12-24 16:10:10',
        id: '450000199302104628',
        pageviews: 1165,
        status: 1,
        place: '1273621637521463'
      }, {
        name: '巡检1',
        type: '食堂安全',
        author: 'name',
        display_time: '2023-12-24 16:10:10',
        id: '450000199302104628',
        pageviews: 1165,
        status: 2,
        place: '1273621637521463'
      }],
      dialogVisible: false,
      title: '巡检任务详情',
      personList: [{ label: '张三', value: '0' }],
      numList: [{ label: '每年', value: '0' }, { label: '每月', value: '1' }, { label: '每日', value: '2' }],
      typeList: [{ label: '消防安全', value: '0' }, { label: '食堂安全', value: '1' }, { label: '护工查房', value: '2' }],
      form: {
      },
      processVoList: [{ status: 0, processName: '东门', percent: '漏检' }, { status: 1, processName: '西门', percent: '已检', time: '2023-12-24 16:10:10' }, { status: 2, processName: '北门', percent: '等待' }]
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      this.list = this.data
      this.listLoading = false
      // getList().then(response => {
      //   this.list = response.data.items
      //   this.listLoading = false
      // })
    },
    detail(row) {
      this.dialogVisible = true
      this.form = JSON.parse(JSON.stringify(row))
    },
    onSubmit() {
      this.$message('submit!')
    },
    onCancel() {
      this.dialogVisible = false
    }
  }
}
</script>
<style scoped lang="scss">
.line {
  text-align: center;
}

.el-step {
  .el-step__head {

    :deep(.is-success) {}
  }

  ::v-deep .el-step__line {
    top: 18px;
  }

  ::v-deep .el-step__head.is-success .el-step__icon.is-text {
    color: #fff !important;
    background: #67c23a !important;
  }
}
</style>
